package com.huslee.shark.alert;

import com.huslee.shark.alert.config.DingtalkConfigs;
import com.huslee.shark.alert.handler.RequestControl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Desc
 * @Author liuzhenke
 * @Create 2021/1/19
 */
@Component
@EnableScheduling
@EnableConfigurationProperties(DingtalkConfigs.class)
@ConditionalOnProperty(prefix = "basealert.dingtalk", name={"asyn"}, matchIfMissing = false)
public class DingtalkAlertAsyn {
    private ExecutorService executor = null;

    @Autowired
    private DingtalkConfigs dingtalkConfigs;

    @PostConstruct
    private void init(){
        executor = Executors.newFixedThreadPool(dingtalkConfigs.getThreads());
    }

    @Scheduled(fixedRate = 10000)
    private void schedule(){
        RequestControl.exec(executor);
    }

}
